/*
 * Wrapper for access to some ezlib functions from C in Symbian 6.0.
 *
 * The problem that is solved here is that some of the functions in
 * ezlib are not extern "C", and thus can notbe called from C code.
 */

#ifdef __cplusplus

#include <ezlib.h>

#else

#ifndef FAR
#define FAR
#endif

#define Z_NO_FLUSH      0
#define Z_OK 0
#define Z_STREAM_END    1
#define MAX_WBITS   15 /* 32K LZ77 window */
typedef unsigned char Byte;  /* 8 bits */
typedef unsigned int uInt;  /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
typedef Byte FAR Bytef;
typedef uLong FAR uLongf;

#define OF(args)  args
typedef void FAR *voidpf;
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void   (*free_func)  OF((voidpf opaque, voidpf address));

struct internal_state;

typedef struct z_stream_s {
    Bytef    *next_in;  /* next input byte */
    uInt     avail_in;  /* number of bytes available at next_in */
    uLong    total_in;  /* total nb of input bytes read so far */

    Bytef    *next_out; /* next output byte should be put there */
    uInt     avail_out; /* remaining free space at next_out */
    uLong    total_out; /* total nb of bytes output so far */

    char     *msg;      /* last error message, NULL if no error */
    struct internal_state FAR *state; /* not visible by applications */

    alloc_func zalloc;  /* used to allocate the internal state */
    free_func  zfree;   /* used to free the internal state */
    voidpf     opaque;  /* private data object passed to zalloc and zfree */

    int     data_type;  /* best guess about the data type: ascii or binary */
    uLong   adler;      /* adler32 value of the uncompressed data */
    uLong   reserved;   /* reserved for future use */
} z_stream;

typedef z_stream FAR *z_streamp;

#define compress(a, b, c, d) compress_wrapper(a, b, c, d)
#define uncompress(a, b, c, d) uncompress_wrapper(a, b, c, d)
#define crc32(a, b, c) crc32_wrapper(a, b, c)
#define inflateInit2(a, b) inflateInit2_wrapper(a, b)
#define inflateEnd(a) inflateEnd_wrapper(a)
#define inflate(a, b) inflate_wrapper(a, b)

#endif // __cplusplus


#ifdef __cplusplus
extern "C" {
#endif

  int compress_wrapper(Bytef *dest, 
                       uLongf *destLen,
                       const Bytef *source, 
                       uLong sourceLen);
  int uncompress_wrapper(Bytef *dest, 
                         uLongf *destLen,
                         const Bytef *source,
                         uLong sourceLen);
  uLong crc32_wrapper(uLong crc, const Bytef *buf, uInt len);
  int inflateInit2_wrapper(z_streamp strm, int windowBits);
  int inflateEnd_wrapper(z_streamp strm);
  int inflate_wrapper(z_streamp strm, int flush);

#ifdef __cplusplus
}
#endif
